import ResultWrapper = require('../ResultWrapper')
import RequestResult = require("../RequestResult")
import RequestListResult = require("../RequestListResult")
import BaseModel = require('../BaseModel')
import ProductCategory = require('../model/ProductCategory')
//code1

//code1

/**
 * 产品分类列表
 */
class StockApiCategories {
    
    get path(): string {
        return '/StockApi/categories'
    }
    
    get isUpload(): boolean {
        return false
    }

    setup(app: any, path: string) {
        console.log('setup service: /' + path)
    }

    //GET
    find(params: any, callback: Function) {
        return this.doWork(params.query)
    }

    doWork(params: any): Promise<any> {

        let page = params.page
        let page_size = params.page_size || RequestListResult.PAGE_SIZE
        /**产品父级分类id, 0表示获取最外层分类列表*/
        let pid: number = params.pid


        let callback = (
            resolve: (data: RequestListResult<ProductCategory>) => void, 
            reject: (error: Error) => void) => {

            let data = new ProductCategory()
            let result = ResultWrapper.wrapList([data])
            result.page = page
            result.page_size = page_size
            result.total_count = 3 * page_size + page_size/2
            result.message = '假数据'

//code2

//code2
            resolve(result)
        }
        return new Promise(callback)
    }
}

export = StockApiCategories